package com.xuecheng.teaching.controller;


import com.xuecheng.commons.model.dto.CommentListDto;
import com.xuecheng.commons.model.dto.CourseCommentDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.CommentListVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.StarRankVo;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.teaching.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 作者
 */
@Slf4j
@RestController
@RequestMapping("/course-comment")
public class CommentController {


    @Autowired
    private CommentService commentService;


    /*
     *评论课程
     *Path： /teaching/course-comment
     * Method： POST
     * Content-Type 	application/json 	是
     * */
    @PostMapping
    public ResponseResult<CommentListVo> comment(@RequestBody CourseCommentDto dto) {
        return commentService.comment(dto);
//        return null;
    }

    /*评论列表
     *Path： /teaching/course-comment/list
     *Method： POST
     * Content-Type 	application/json 	是
     * */
    @PostMapping("/list")
    public ResponseResult<CommentListVo> forcommentlist(@RequestBody CommentListDto dto, PageRequest request) {
        System.out.println(dto);
        System.out.println(request);
        return commentService.forlist(dto, request);
    }

    /* 用户端    评论列表
     *Path： /teaching/course-comment/list
     *Method： POST
     * Content-Type 	application/json 	是
     * */
    @PostMapping("/for-course")
    public ResponseResult<List<CommentListVo>> commentlist(@RequestBody CommentListDto dto) {
        return commentService.commentlist(dto);
    }

    /*
     *   后台管理系统 删除评论
     * Path： /content/m/course-comment/{commentId}
     * Method： DELETE
     * commentId 		评论ID
     * */
    @DeleteMapping("/{commentId}")
    public ResponseResult delete(@PathVariable long commentId) {
        return commentService.delete(commentId);
    }

    /*
     * 课程评论统计 课程发布id  星星统计
     *Path： /teaching/course-comment/course/{targetId}
     * Method： GET
     * targetId 		课程发布id
     * */
    @GetMapping("/course-statistics/{targetId}")
    public ResponseResult<StarRankVo> courseReplyStatistical(@PathVariable long targetId) {
        return commentService.courseReplyStatistical(targetId);
    }

    /*
     *  后台管理系统  机构的评论列表
     * Path： /content/m/course-comment/list-all
     * Method： GET
     * Content-Type 	application/json 	是
     * */
    @PostMapping("/listAll")
    public ResponseResult<CommentListVo> listAll(@RequestBody CommentListDto dto) {
        return commentService.listAll(dto);
    }
}
